import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.0
import QtQuick.Controls.Styles 1.0

Item {

    /// \brief This property is a dummy and currently doesn't have any functionality
    property int editIndex

    TitleText {
        id: titleText

        color: "white"
        text: "Skills Table"

        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right

        anchors.leftMargin: 6
    }

    Flickable {
        id: contentFlickable
        anchors.top: titleText.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.margins: 12

        Column
        {
            anchors.right: parent.right
            anchors.left: parent.left

            Rectangle {
                id: titleRectangle
                height: 20
                anchors.right: parent.right
                anchors.left: parent.left
                color: "darkred"
                border.color: "white"
                border.width: 1

                Row {
                    spacing: 6
                    anchors.fill: parent
                    anchors.leftMargin: 6

                    Text {
                        text: "Skill/Character Class"
                        id: rowTitleText
                        color: "white"
                        width: 150
                        anchors.verticalCenter: parent.verticalCenter
                    }

                    Repeater {
                        model: characterModel
                        delegate: Text {
                            text: acronym
                            color: "white"
                            font.bold: true
                            horizontalAlignment: Text.AlignHCenter
                            width: 50
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                }

            }

            Repeater {
                id: rowRepeater
                model: skillsModel

                delegate: Rectangle {
                    id: rowRectangle
                    property string skillName: name
                    height: 20
                    anchors.right: parent.right
                    anchors.left: parent.left
                    Row {
                        spacing: 6
                        anchors.fill: parent
                        anchors.leftMargin: 6
                        Text {
                            color: "white"
                            text: rowRectangle.skillName + " (" + attributeList.get(attribute).name.slice(0,3) + ")"
                            width: 150
                            anchors.verticalCenter: parent.verticalCenter
                            font.bold: true
                        }

                        Repeater {
                            model: characterModel
                            delegate: Text {
                                color: "white"
                                text: skills.search(rowRectangle.skillName) >= 0 ? "cc" : "-"
                                width: 50
                                anchors.verticalCenter: parent.verticalCenter
                                horizontalAlignment: Text.AlignHCenter
                            }

                        }
                    }

                    MouseArea {
                        id: rowMouseArea
                        anchors.fill: parent
                        hoverEnabled:true
                    }
                    color: rowMouseArea.containsMouse ? "steelblue" : !(index%2) ? "transparent" : "#888888"
                }
            }

            Rectangle
            {
                id: totalsRectangle
                height: 20
                anchors.right: parent.right
                anchors.left: parent.left
                color: "midnightblue"
                border.color: "white"
                border.width: 1

                Row {
                    spacing: 6
                    anchors.fill: parent
                    anchors.leftMargin: 6
                    Text {
                        color: "white"
                        text: "Total"
                        width: 150
                        anchors.verticalCenter: parent.verticalCenter
                    }

                    Repeater {
                        model: characterModel
                        delegate: Text {
                            color: "white"
                            text: skills.split(";").length
                            width: 50
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }
            }

        }
    }

}
